home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
win
/
mewldemo.zip
/
MEWLDEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-12-15
|
64KB
|
2,021 lines
#if 0
#define MODELESSTEST
#define CTLCOLOR_TEST
#endif
/*===========================================================================*/
/* */
/* File : MEWLDEMO.C */
/* */
/* Purpose : General purpose demo of the MEWEL Window Library */
/* */
/* History : */
/* */
/* (C) Copyright 1989 Marc Adler/Magma Systems All Rights Reserved */
/*===========================================================================*/
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <limits.h>
#ifndef UNIX
#include <io.h>
#include <dos.h>
#endif
#include "window.h"
typedef long (PASCAL *TIMERPROC)();
#define ID_MENUBAR 10
#define ID_NOTEPAD 12
#define ID_ABOUT 98
#define ID_COMBOBOX 97
#define ID_EXIT 99
#define ID_LISTDEMO 200
#define ID_TIMEDEMO 201
#define ID_MOUSEDEMO 202
#define ID_MENUDEMO 203
#define ID_FILEDEMO 204
#define ID_EDITDEMO 205
#define ID_EXECDEMO 206
#define ID_CALCDEMO 207
#define ID_CHILDDEMO 208
#define ID_GRAPHICS 213
#define ID_TOGGLEEGA 214
#define ID_COMBODEMO 210
#define ID_STRING 100
#define ID_POS 101
#define ID_FRAME 102
#define ID_APPEND 103
#define ID_INSERT 104
#define ID_DELETE 105
#define ID_LISTBOX 106
#define ID_STOP 100
#define ID_START 101
#define ID_INTERVAL 105
#define ID_WORD50 300
#define ID_WRITE 301
#define ID_EXCEL 302
#define ID_124 303
#define ID_C52 304
#define ID_QUICKC 305
#define ID_QUICKBASIC 306
#define ID_PASCAL 307
#define ID_NEW 200
#define ID_OPEN 201
#define ID_SAVE 202
#define ID_SAVEAS 203
#define ID_HELP 299
#define ID_COPY 510
#define ID_CUT 511
#define ID_PASTE 512
#define ID_CLEAR 513
#define ID_GETLEN 520
#define ID_GETLINES 521
#define ID_GETHANDLE 522
#define IDM_MEMAVAIL 600
#define IDS_MAINTITLE 500
#ifdef __TURBOC__
#include <alloc.h>
extern unsigned _stklen = 20000;
#endif
typedef struct dlgTemplate
{
BYTE *szClass;
BYTE *szTitle;
DWORD dwStyle;
int x, y, width, height;
WORD idCtrl;
} DTEMPLATE;
/*
A dialog box definition for creating dialog boxes on-the-fly
*/
DTEMPLATE IntervalDialogTemplate[] =
{
{ (PSTR) "Text", (PSTR) "Interval:", 0x0000, 27,10, 9, 1, 0 },
{ (PSTR) "Edit", (PSTR) NULL, WS_BORDER | WS_TABSTOP | WS_GROUP, 38,10, 6, 1,ID_INTERVAL},
{ (PSTR) "PushButton", (PSTR) "~OK", BS_DEFAULT | WS_TABSTOP | WS_GROUP,30,12, 4, 1,IDOK },
{ (PSTR) "PushButton", (PSTR) "~CANCEL", WS_TABSTOP | WS_GROUP, 39,12, 8, 1,IDCANCEL },
};
/*
Function declarations
*/
extern int main(int argc,char * *argv);
extern int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
extern BOOL InitApp(HANDLE hInstance);
extern LONG PASCAL MainWndProc(HWND hWnd,WORD message,WORD wParam,LONG lParam);
extern LONG PASCAL NotepadWndProc();
extern HWND PASCAL DialogCreateIndirect(HWND hParent,int row1,int col1,int row2,int col2,BYTE *szTitle,WORD attr,DWORD fFlags,int (PASCAL *pfnDlgProc)(),struct dlgTemplate *pTemplate,int nTemplate);
extern int PASCAL ListboxDialogProc(HWND hDlg,WORD message,WORD wParam,DWORD lParam);
extern void TimerDemo(void );
extern WORD TimerMenuInit(void);
extern long PASCAL TimerWndProc(HWND hWnd,WORD msg,WORD wParam,LONG lParam);
extern void NewInterval(HWND hWnd);
extern int PASCAL IntervalDlgProc(HWND hDlg,WORD msg,WORD wParam,DWORD lParam);
extern int AreTimersRunning(void );
extern void KillAllTimers(void );
extern int MouseDemo(void );
extern int PrintScrollbarValues(WORD message,WORD wParam,LONG lParam);
extern void DoFloatingPopup(void );
extern void ComboDemo(void);
extern int PASCAL ComboDialogProc(HWND hDlg,WORD msg,WORD wParam,DWORD lParam);
extern int NotePad(void );
extern int NotepadOpenFile(BYTE *fname);
extern long PASCAL NotepadWndProc(HWND hWnd,WORD message,WORD wParam,LONG lParam);
extern void DOSEscape(void );
extern int Calculator(void );
extern void ShowNumber(HWND hWnd,DWORD dwNumber);
extern DWORD CalcIt(DWORD dwFirstNum,WORD nOperation,DWORD dwNum);
extern int PASCAL DlgProc(HWND hWnd,WORD iMessage,WORD wParam,DWORD lParam);
extern int BadCommand(void );
extern void ChildDemo(void );
extern long PASCAL PanelWndProc(HWND hWnd,WORD message,WORD wParam,LONG lParam);
extern void CreateChildren(HWND hParent);
extern void TerminateChildDemo(void );
extern void GraphicsModeDemo(void );
extern void VideoModeDemo(void );
extern long memavail(void );
/*
Global Window Handles
*/
HWND hMain;
HWND hMsgWnd;
HWND hWndTime;
HWND hMouseWnd = NULLHWND;
HWND hWndCalc = NULLHWND;
#ifdef MODELESSTEST
HWND hWndListbox = NULLHWND;
HWND hWndString;
#endif
HANDLE hInstance = 0;
main(int argc, char **argv)
{
(void) argv; (void) argc;
/*
Initialize the window system - this *must* be done once in every appl
*/
WinInit();
WinUseSysColors(NULLHWND, TRUE);
//SET_PROGRAM_STATE(STATE_DEFER_VIRTSCREEN);
#ifdef CTLCOLOR_TEST
SetWindowsCompatibility(WC_SEND_WMCTLCOLOR);
#endif
bMessageBoxHasShadow = TRUE;
#if 0
#if !defined(UNIX) && !defined(OS2) && !defined(VMS)
/*
If you want nice VGA fonts, make this call!
*/
VidInitVGAFonts();
#endif
#endif
#if defined(UNIX) || defined(OS2) || defined(VMS)
hInstance = OpenResourceFile("mewldemo");
#endif
return WinMain(hInstance, 0, NULL, SW_SHOW);
}
int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
HANDLE hInstance, hPrevInstance;
LPSTR lpszCmdLine;
int nCmdShow;
{
MSG msg;
HWND hMenu, hPop;
WORD hRes;
char szBuf[64];
HACCEL hAccel;
static int iLastSec = -1;
(void) lpszCmdLine;
/*
Register the main window class.
*/
if (!hPrevInstance)
if (!InitApp(hInstance))
exit(1);
/*
Create the main window and set the main window procedure
*/
LoadString(hInstance, IDS_MAINTITLE, (LPSTR) szBuf, sizeof(szBuf));
hMain = CreateWindow("Mewldemo", /* class */
szBuf, /* title */
WS_BORDER | /* dwStyle */
WS_CLIP |
WS_SYSMENU | WS_CAPTION | WS_VSCROLL | WS_HSCROLL,
CW_USEDEFAULT,0, /* x,y,width,height */
CW_USEDEFAULT,0, /* x,y,width,height */
NULLHWND, /* hParent */
NULLHWND, /* hMenu */
hInstance, /* hInst */
0L); /* lpParam */
/*
Load in the accelerator table
*/
hAccel = LoadAccelerators(hInstance, (LPSTR) "Mewldemo");
/*
Create a child window to display the output messages.
*/
hMsgWnd = CreateWindow("Normal", /* class */
NULL, /* title */
WS_CLIP, /* dwStyle */
1, GetSystemMetrics(SM_CYSCREEN) - 2,
42, 1,
hMain, /* hParent */
NULLHWND, /* hMenu */
hInstance, /* hInst */
0L); /* lpParam */
/*
Create a window for the clock
*/
hWndTime = CreateWindow("Normal",
NULL,
WS_CLIP,
45, GetSystemMetrics(SM_CYSCREEN) - 2,
11, 1,
hMain, /* hParent */
NULLHWND, /* hMenu */
0, /* hInst */
0L); /* lpParam */
/*
Show the window
*/
ShowWindow(hMain, nCmdShow);
UpdateWindow(hMain);
/*
Main message loop
*/
for (;;)
{
/*
This is how you can do background processing
*/
while (!PeekMessage(&msg, NULLHWND, 0, 0, PM_REMOVE))
{
int h, m, s;
char szTime[16];
DosGetTime(&h, &m, &s);
if (s != iLastSec)
{
sprintf(szTime, "%02d:%02d:%02d", h, m, s);
WinPuts(hWndTime, 0, 0, szTime, WinGetAttr(hWndTime));
iLastSec = s;
}
}
if (msg.message == WM_QUIT)
break;
if (msg.message == WM_MOUSEMOVE && hMouseWnd)
{
POINT pt;
pt = MAKEPOINT(msg.lParam);
sprintf(szBuf, "ROW [%2d] COL [%2d]", pt.y, pt.x);
WinPutsCenter(hMouseWnd, 0, (PSTR) szBuf, 0x31);
}
if (hWndCalc && IsDialogMessage(hWndCalc, &msg))
continue;
#ifdef MODELESSTEST
if (hWndListbox && IsDialogMessage(hWndListbox, &msg))
continue;
#endif
if (!TranslateAccelerator(hMain, hAccel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
/****************************************************************************/
/* */
/* Function : InitApp */
/* */
/* Purpose : Registers the window class */
/* */
/* Returns : */
/* */
/****************************************************************************/
BOOL InitApp(hInstance)
HANDLE hInstance;
{
HANDLE hClass;
PWNDCLASS pClass;
hClass = LocalAlloc(LPTR, sizeof(WNDCLASS));
pClass = (PWNDCLASS) LocalLock(hClass);
pClass->hCursor = LoadCursor(NULL, IDC_ARROW);
pClass->hIcon = (HICON) NULL;
pClass->lpszMenuName = "MainMenu";
pClass->lpszClassName = "Mewldemo";
pClass->hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
pClass->hInstance = hInstance;
pClass->style = CS_HREDRAW | CS_VREDRAW;
pClass->lpfnWndProc = MainWndProc;
if (!RegisterClass((LPWNDCLASS) pClass))
/*
* Initialization failed. Windows will automatically deallocate all
* allocated memory.
*/
return FALSE;
/*
Register the notepad class
*/
pClass->lpszMenuName = (LPSTR) "NotePad";
pClass->lpszClassName = "NotePad";
pClass->lpfnWndProc = NotepadWndProc;
if (!RegisterClass((LPWNDCLASS) pClass))
return FALSE;
LocalUnlock(hClass);
LocalFree(hClass);
return TRUE; /* Initialization succeeded */
}
/****************************************************************************/
/* */
/* Function : MainWndProc */
/* */
/* Purpose : Window procedure for the main window. */
/* */
/* Returns : */
/* */
/****************************************************************************/
long PASCAL MainWndProc(HWND hWnd, WORD message, WORD wParam, LONG lParam)
{
BYTE buf[80];
switch (message)
{
case WM_COMMAND :
/*
See if the user chose a demo from the DEMO menubar item
*/
switch (wParam)
{
#ifdef DOS
case IDM_MEMAVAIL :
{
char msg[80];
sprintf(msg, " Available memory is: %lu kB ", memavail() / 1024 );
MessageBox(hMain, msg, "Available memory", MB_OK);
break;
}
#endif
case ID_CALCDEMO :
Calculator();
break;
case ID_LISTDEMO :
if (AreTimersRunning())
KillAllTimers();
#ifdef MODELESSTEST
if ((hWndListbox =
CreateDialog(hInstance,"ListDemoDlg",hMain,ListboxDialogProc)) != NULL)
{
ShowWindow(hWndListbox, SW_SHOW);
SetFocus(hWndListbox);
hWndString = GetDlgItem(hWndListbox, ID_STRING);
}
#else
DialogBox(hInstance, "ListDemoDlg", hMain, ListboxDialogProc);
#endif
break;
case ID_TIMEDEMO :
if (AreTimersRunning())
KillAllTimers();
TimerDemo();
break;
case ID_MOUSEDEMO:
if (hMouseWnd)
{
DestroyWindow(hMouseWnd);
hMouseWnd = NULLHWND;
CheckMenuItem(GetMenu(hMain), ID_MOUSEDEMO, MF_UNCHECKED);
}
else
{
MouseDemo();
CheckMenuItem(GetMenu(hMain), ID_MOUSEDEMO, MF_CHECKED);
}
break;
case ID_MENUDEMO:
DoFloatingPopup();
break;
case ID_FILEDEMO :
/*
DlgOpenFile is an undocumented MEWEL call which displays a
standard file-open dialog box.
*/
if (DlgOpenFile(NULLHWND, (PSTR) "*.*", buf))
{
char msg[80];
sprintf(msg, "You chose %s", buf);
MessageBox(hMain, buf, "Files Demo", MB_OK);
}
break;
case ID_EDITDEMO :
NotePad();
break;
case ID_EXECDEMO :
DOSEscape();
break;
case ID_CHILDDEMO:
ChildDemo();
break;
case ID_EXIT :
PostQuitMessage(0);
break;
case ID_COMBODEMO:
ComboDemo();
break;
case ID_GRAPHICS :
GraphicsModeDemo();
break;
case ID_TOGGLEEGA :
VideoModeDemo();
break;
case ID_WORD50 :
MessageBox(NULLHWND, (PSTR) "You chose Word 5.0", (PSTR) "WM_COMMAND", MB_OK);
break;
case ID_WRITE :
MessageBox(NULLHWND, (PSTR) "You chose WRITE", (PSTR) "WM_COMMAND", MB_OK);
break;
case ID_EXCEL :
MessageBox(NULLHWND, (PSTR) "You chose EXCEL", (PSTR) "WM_COMMAND", MB_OK);
break;
case ID_124 :
MessageBox(NULLHWND, (PSTR) "You chose 1+2=4", (PSTR) "WM_COMMAND", MB_OK);
break;
case ID_C52 :
MessageBox(NULLHWND, (PSTR) "You chose C 5.2", (PSTR) "WM_COMMAND", MB_OK);
break;
case ID_QUICKC :
MessageBox(NULLHWND, (PSTR) "You chose QUICK C", (PSTR) "WM_COMMAND", MB_OK);
break;
case ID_QUICKBASIC :
MessageBox(NULLHWND, (PSTR) "You chose QUICK BASIC", (PSTR) "WM_COMMAND", MB_OK);
break;
case ID_PASCAL :
MessageBox(NULLHWND, (PSTR) "You chose PASCAL", (PSTR) "WM_COMMAND", MB_OK);
break;
case ID_ABOUT :
MessageBox(NULLHWND, (PSTR) "MEWEL Window System\nMagma Systems\n(201) 912-0192",
(PSTR) "About MEWEL", MB_OK | MB_ICONASTERISK);
break;
case ID_HELP :
goto do_help;
}
break;
case WM_CHAR :
if (wParam == VK_CTRL_BREAK)
MessageBox(hMain, (PSTR) "You hit the CTRL+BREAK key", (PSTR) "Warning", MB_OK);
break;
case WM_VSCROLL :
case WM_HSCROLL :
PrintScrollbarValues(message, wParam, lParam);
break;
case WM_HELP :
do_help:
MessageBox(hWnd,
"MEWEL Demonstration Program\nMagma Systems\n15 Bodwell Terrace\nMillburn, NJ 07041\n\
(201) 912-0192 (voice)\n(201) 912-0668 (BBS)\n(201) 912-0103 (FAX)",
"MEWLDEMO", MB_OK | MB_ICONASTERISK);
break;
case WM_MENUSELECT :
{
WORD idMenu;
WORD iLen;
/*
We trigger off of the WM_MENUSELECT message so that we
can print informative messages about each menu option.
*/
/*
An actual menu item identifier is returned in wParam...
*/
idMenu = wParam;
/*
If lParam was <-1,0>, then the user dismissed the menu, so
we just want to erase the previous help text from the
status window. If not, then idMenu contains a valid menu or
submenu identifier. Load the corresponding string from
the string table, and print it.
*/
if (LOWORD(lParam) == 0 && HIWORD(lParam) == 0 ||
LoadString(hInstance, idMenu, (LPSTR) buf, sizeof(buf)) > 0)
{
WinClear(hMsgWnd);
if (LOWORD(lParam) == 0 && HIWORD(lParam) == 0)
;
else
WinPuts(hMsgWnd, 0, 0, buf, WinGetAttr(hMsgWnd));
}
else
WinClear(hMsgWnd);
break;
}
#ifdef MODELESSTEST
case WM_INITMENUPOPUP :
if (hWndListbox && hWndString)
{
DWORD iSel = SendMessage(hWndString, EM_GETSEL, 0, 0L);
if (iSel)
iSel++; // dummy
}
break;
#endif
case WM_DEVMODECHANGE :
/*
Probably toggled between 25 and 43/50 line modes
*/
WinSetSize(hWnd,GetSystemMetrics(SM_CYSCREEN),GetSystemMetrics(SM_CXSCREEN));
WinMove(hMsgWnd,GetSystemMetrics(SM_CYSCREEN) - 2, 1);
WinMove(hWndTime,GetSystemMetrics(SM_CYSCREEN) - 2,45);
break;
default :
/* Call the default window procedure for the main window */
return DefWindowProc(hWnd, message, wParam, lParam);
}
return FALSE;
}
/****************************************************************************/
/* */
/* Function : DialogCreateIndirect() */
/* */
/* Purpose : A function you can use to build dialog boxes on-the-fly. */
/* */
/* Returns : The handle of the created dialog box */
/* */
/****************************************************************************/
HWND PASCAL DialogCreateIndirect(HWND hParent,
int row1, int col1, int row2, int col2,
BYTE *szTitle,
WORD attr, DWORD fFlags,
int (PASCAL *pfnDlgProc)(),
DTEMPLATE *pTemplate, int nTemplate)
{
HDLG hDlg;
HWND hCtrl;
hDlg = DialogCreate(hParent,row1,col1,row2,col2,szTitle,attr,fFlags,pfnDlgProc,0,NULL);
if (hDlg == NULLHWND)
return NULLHWND;
while (nTemplate-- > 0)
{
hCtrl = _CreateWindow(pTemplate->szClass, pTemplate->szTitle,
pTemplate->dwStyle,
pTemplate->x, pTemplate->y,
pTemplate->width, pTemplate->height,
0x31, pTemplate->idCtrl,
hDlg, /* hParent */
(HMENU) NULLHWND, /* hMenu */
0, /* hInst */
(DWORD) NULL); /* lpCreateParams */
if (hCtrl == NULLHWND)
return NULLHWND;
pTemplate++;
}
return (HWND) hDlg;
}
/****************************************************************************/
/* */
/* Function : ListDemo() */
/* */
/* Purpose : Code to implement the listbox demo */
/* */
/* Returns : */
/* */
/****************************************************************************/
int PASCAL ListboxDialogProc(HWND hDlg, WORD message, WORD wParam, DWORD lParam)
{
BYTE szString[130];
BYTE szPos[30];
int iPos;
int operation;
int iSel;
static BYTE szItemText[130];
static int nMovedItem = - 1;
#ifdef MODELESSTEST
static HBRUSH hBlueBrush = 0;
#endif
switch (message)
{
case WM_INITDIALOG :
SendDlgItemMessage(hDlg, ID_STRING, EM_SETSEL, 0, (DWORD) 0x7FFF);
SendDlgItemMessage(hDlg, ID_POS, EM_SETSEL, 0, (DWORD) 0x7FFF);
CheckRadioButton(hDlg, ID_APPEND, ID_DELETE, ID_APPEND);
#ifdef MODELESSTEST
if (!hBlueBrush)
{
hBlueBrush = CreateSolidBrush(RGB(0, 0, 255));
SetWindowsCompatibility(WC_SEND_WMCTLCOLOR);
}
#endif
return TRUE;
case WM_CHAR :
if (wParam == VK_ALT_M && GetDlgItem(hDlg, ID_LISTBOX) == GetFocus())
{
if (nMovedItem < 0)
{
nMovedItem = (int) SendDlgItemMessage(hDlg,ID_LISTBOX,LB_GETCURSEL,0,0L);
SendDlgItemMessage(hDlg, ID_LISTBOX, LB_GETTEXT,
nMovedItem, (DWORD) (BYTE far *) szItemText);
}
else
nMovedItem = -1;
return TRUE;
}
if (wParam == VK_ALT_K && GetDlgItem(hDlg, ID_LISTBOX) == GetFocus())
{
SendDlgItemMessage(hDlg, ID_LISTBOX, LB_RESETCONTENT, 0, 0L);
}
break;
case WM_VALIDATE :
if (wParam == ID_POS)
{
GetDlgItemText(hDlg, ID_POS, (LPSTR) szString, sizeof(szString));
if (!isdigit(szString[0]) && szString[0] != '\0')
return -1;
}
return TRUE;
case WM_COMMAND :
switch (wParam)
{
case IDOK :
/*
The user pressed the OK button. We want to get the string
that is to be inserted as well as the position.
*/
GetDlgItemText(hDlg, ID_STRING, (LPSTR) szString, sizeof(szString));
iPos = GetDlgItemInt(hDlg, ID_POS, NULL, TRUE);
/*
Determine the operation to perform
*/
operation = 0;
if (IsDlgButtonChecked(hDlg, ID_APPEND))
operation = LB_ADDSTRING;
else if (IsDlgButtonChecked(hDlg, ID_INSERT))
operation = LB_INSERTSTRING;
else if (IsDlgButtonChecked(hDlg, ID_DELETE))
operation = LB_DELETESTRING;
if (operation)
{
SendDlgItemMessage(hDlg, ID_LISTBOX, operation, iPos,
(DWORD) (BYTE far *) szString);
MessageBox(NULLHWND, szString, (PSTR) "Completed", MB_OK | MB_ICONEXCLAMATION);
}
break;
case IDCANCEL :
/*
If the user pressed the QUIT button, then send a WM_QUIT
message to all the window procs
*/
EndDialog(hDlg, 0);
break;
case ID_LISTBOX :
switch (HIWORD(lParam))
{
case LBN_SELCHANGE :
if (nMovedItem < 0)
return FALSE;
iSel = (int) SendDlgItemMessage(hDlg,ID_LISTBOX,LB_GETCURSEL,0,0L);
SendDlgItemMessage(hDlg,ID_LISTBOX,LB_DELETESTRING,nMovedItem,0L);
SendDlgItemMessage(hDlg,ID_LISTBOX,LB_INSERTSTRING,iSel,
(DWORD) (BYTE far *) szItemText);
nMovedItem = iSel;
break;
}
return FALSE;
case ID_POS :
if (HIWORD(lParam) == FN_ERRVALIDATE)
{
MessageBox(hDlg, (PSTR) "Bad format for position",
(PSTR) "Format Error", MB_OK | MB_ICONHAND);
}
break;
}
return TRUE;
#ifdef MODELESSTEST
case WM_SETFOCUS :
SetFocus(GetDlgItem(hDlg, ID_STRING));
return TRUE;
case WM_CTLCOLOR :
if (HIWORD(lParam) == CTLCOLOR_EDIT)
{
HBRUSH hBrush = hBlueBrush;
SetTextColor(wParam, RGB(0, 255, 255)); // cyan fore
SetBkColor(wParam, RGB(0, 0, 255)); // blue background
return hBrush;
}
else
return GetStockObject(WHITE_BRUSH);
case WM_CLOSE :
hWndListbox = NULLHWND;
DestroyWindow(hDlg);
return TRUE;
#endif
}
return FALSE;
}
/**************************************************************************/
/* */
/* TIMER DEMO */
/* */
/**************************************************************************/
#define NUMTIMERS 8
HWND hTimerWnd[NUMTIMERS];
extern long PASCAL TimerWndProc(HWND, WORD, WORD, LONG);
VOID TimerDemo(VOID)
{
int i;
HWND hWnd;
HMENU hMenu;
char title[16];
MessageBox(hMain,
(PSTR) "The timer strings will occasionally overwrite the child windows.\nTHIS IS NOT A BUG.",
(PSTR) "Heed this", MB_OK | MB_ICONEXCLAMATION);
for (i = 1; i <= NUMTIMERS; i++)
{
sprintf(title, "Timer %d", i);
hWnd = hTimerWnd[i-1] =
CreateWindow((PSTR) "Normal", /* class */
(PSTR) title, /* title */
WS_BORDER | WS_CLIP, /* dwStyle */
((i-1)%2) ? 40 : 20,
((i-1)/2)*5 + 3,
25, 4,
hMain, /* hParent */
NULLHWND, /* hMenu */
0, /* hInst */
0L); /* lpParam */
WinSetWinProc(hWnd, TimerWndProc);
hMenu = TimerMenuInit();
SetMenu(hWnd, hMenu);
SetTimer(hWnd, i, i*1000, (FARPROC) NULL);
}
ShowWindow(hMain, TRUE);
SetFocus(hTimerWnd[0]);
}
HMENU TimerMenuInit()
{
HMENU hMenu, hPop;
/*
Create the menu bar
*/
hMenu = CreateMenu();
/*
Create a pulldown
*/
hPop = CreateMenu();
ChangeMenu(hPop, 0, (PSTR) "~Stop", ID_STOP, MF_APPEND);
ChangeMenu(hPop, 0, (PSTR) "~Interval", ID_INTERVAL, MF_APPEND);
ChangeMenu(hPop, 0, (PSTR) "E~xit", ID_EXIT, MF_APPEND);
/*
Attach each of the pulldowns to their corresponding menubar entries
*/
ChangeMenu(hMenu, 0, (PSTR) "~Timer", hPop, MF_POPUP | MF_APPEND);
return hMenu;
}
long PASCAL TimerWndProc(HWND hWnd, WORD msg, WORD wParam, LONG lParam)
{
char szTime[80];
int hrs, min, sec;
int i;
switch (msg)
{
case WM_TIMER :
DosGetTime(&hrs, &min, &sec);
sprintf(szTime, "%02d:%02d:%02d", hrs, min, sec);
WinPutsCenter(hWnd, 0, (PSTR) szTime, WinGetAttr(hWnd));
SoundNote(CNOTE + wParam, MIN_OCTAVE + wParam, 100);
return TRUE;
case WM_CHAR :
if (wParam == VK_TAB)
{
for (i = 1; i <= NUMTIMERS; i++)
if (hTimerWnd[i-1] == hWnd)
{
SetFocus(hTimerWnd[ (i == NUMTIMERS) ? 0 : i ]);
return TRUE;
}
}
break;
case WM_SETFOCUS :
BringWindowToTop(hWnd);
return DefWindowProc(hWnd, msg, wParam, lParam);
case WM_COMMAND :
switch (wParam)
{
case ID_EXIT :
case ID_STOP :
for (i = 1; i <= NUMTIMERS; i++)
if (hTimerWnd[i-1] == hWnd)
{
KillTimer(hWnd, i);
ChangeMenu(GetSubMenu(GetMenu(hWnd), 0),
0, (PSTR) "Start", ID_START, MF_CHANGE | MF_STRING);
}
if (wParam == ID_EXIT)
{
/*
Setting focus to a non-timer window will eliminate the
situation where DestroyWindow(), detecting that the
window with the focus is being destroyed, sets the focus
to the next timer window (which will only be destroyed
in the next interation of the for loop). This will speed
up the process of destruction.
*/
SetFocus(hMain);
for (i = 1; i <= NUMTIMERS; i++)
{
DestroyWindow(hTimerWnd[i-1]);
hTimerWnd[i-1] = NULLHWND;
}
}
break;
case ID_START:
for (i = 1; i <= NUMTIMERS; i++)
if (hTimerWnd[i-1] == hWnd)
{
SetTimer(hWnd, i, i*1000, (FARPROC) NULL);
ChangeMenu(GetSubMenu(GetMenu(hWnd), 0),
0, (PSTR) "Stop", ID_STOP, MF_CHANGE | MF_STRING);
}
break;
case ID_INTERVAL :
NewInterval(hWnd);
break;
}
return TRUE;
default :
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return TRUE;
}
VOID NewInterval(HWND hWnd)
{
HDLG hDlg;
int i, tid;
unsigned interval;
extern int PASCAL IntervalDlgProc();
for (i = 1; i <= NUMTIMERS; i++)
if (hTimerWnd[i-1] == hWnd)
{
tid = i;
break;
}
hDlg = DialogCreateIndirect(NULLHWND,
8,26,13,51,
(PSTR) "New Interval",
0x31,0L,IntervalDlgProc,
IntervalDialogTemplate,
sizeof(IntervalDialogTemplate) / sizeof(DTEMPLATE));
if ((interval = _DialogBox(hDlg)) != IDCANCEL)
{
KillTimer(hWnd, tid);
SetTimer(hWnd, tid, interval, (FARPROC) NULL);
}
}
int PASCAL IntervalDlgProc(HWND hDlg, WORD msg, WORD wParam, DWORD lParam)
{
char szInterval[80];
(void) lParam;
switch (msg)
{
case WM_INITDIALOG :
return TRUE;
case WM_COMMAND :
if (wParam == IDCANCEL)
EndDialog(hDlg, IDCANCEL);
else if (wParam == IDOK)
{
GetDlgItemText(hDlg, ID_INTERVAL, (BYTE far *) szInterval, 65);
EndDialog(hDlg, atoi(szInterval));
}
return TRUE;
default :
return FALSE;
}
}
int AreTimersRunning(VOID)
{
return hTimerWnd[0];
}
VOID KillAllTimers(VOID)
{
SendMessage(hTimerWnd[0], WM_COMMAND, ID_EXIT, 0L);
}
/**************************************************************************/
/* */
/* MOUSE DEMO */
/* */
/**************************************************************************/
int MouseDemo(VOID)
{
#ifndef UNIX
if (!GetSystemMetrics(SM_MOUSEPRESENT))
{
MessageBox(NULLHWND, (PSTR) "You must have a mouse to run this demo.",
(PSTR) "Error",MB_OK);
return FALSE;
}
hMouseWnd = _CreateWindow((PSTR) "Normal", /* class */
(PSTR) "Mouse Coordinates", /* title */
WS_BORDER | WS_CLIP, /* dwStyle */
30,10, 20,3, /* x,y,width,height */
0x31, /* attr */
1, /* id */
hMain, /* hParent */
NULLHWND, /* hMenu */
0, /* hInst */
0L); /* lpParam */
ShowWindow(hMain, TRUE);
return TRUE;
#endif
}
/**************************************************************************/
/* */
/* POPTEST.C - demonstration of the usage of floating popups */
/* */
/**************************************************************************/
VOID DoFloatingPopup(VOID)
{
HMENU hMenu;
if ((hMenu = LoadPopupMenu(hInstance, (LPSTR) "FloatingPopup")) != NULL)
TrackPopupMenu(hMenu, 0,30,10,20, hMain, (LPRECT) NULL);
}
/*===========================================================================*/
/* */
/* File : MOVETEST.C */
/* */
/* Purpose : Demo of child windows. Included moving, resizing, and clipping */
/* */
/* History : */
/* */
/* (C) Copyright 1989 Marc Adler/Magma Systems All Rights Reserved */
/*===========================================================================*/
extern long PASCAL PanelWndProc();
HWND hPanel1, hPanel2, hPanel3;
static PSTR pszChildMsg = (PSTR)
"You can move (drag the caption) or resize (drag lower-right corner)\n\
any of the 3 child windows.\n You can press the arrow keys to scroll\n\
the panels. This also demonstrates MEWEL clipping sibling windows.";
VOID ChildDemo(VOID)
{
HANDLE hMemory;
PWNDCLASS pWndClass;
TerminateChildDemo();
MessageBox(hMain, pszChildMsg, (PSTR) "Child Demo", MB_OK);
hMemory = LocalAlloc(LPTR, sizeof(WNDCLASS));
pWndClass = (PWNDCLASS) LocalLock(hMemory);
pWndClass->hCursor = LoadCursor(NULL, IDC_ARROW);
pWndClass->hIcon = LoadIcon(NULLHWND, IDI_APPLICATION);
pWndClass->lpszMenuName = NULL;
pWndClass->lpszClassName = "Panel";
pWndClass->lpfnWndProc = PanelWndProc;
RegisterClass(pWndClass);
LocalUnlock(hMemory);
LocalFree(hMemory);
hPanel1=_CreateWindow((PSTR) "Panel", /* class */
(PSTR) "Panel1", /* title */
WIN_HAS_BORDER | WIN_HAS_SHADOW | SHADOW_BOTRIGHT |
WIN_SYSMENU | WIN_TITLEBAR | WIN_MINMAXBOX |
WIN_VSCROLL | WIN_HSCROLL | WIN_MOVEBOX | WIN_SIZEBOX |
WS_CLIP,
4,3, 30,14, /* x,y,width,height */
MAKE_ATTR(WHITE, RED),
1, /* id */
hMain, /* hParent */
NULLHWND, /* hMenu */
0, /* hInst */
0L); /* lpParam */
CreateChildren(hPanel1);
hPanel2= _CreateWindow((PSTR) "Panel", /* class */
(PSTR) "Panel2", /* title */
WIN_HAS_BORDER | WIN_HAS_SHADOW | SHADOW_BOTRIGHT |
WIN_SYSMENU | WIN_TITLEBAR | WIN_MINMAXBOX |
WIN_VSCROLL | WIN_HSCROLL | WIN_MOVEBOX | WIN_SIZEBOX |
WS_CLIP,
24,6, 30,14, /* x,y,width,height */
MAKE_ATTR(WHITE, BLUE),
2, /* id */
hMain, /* hParent */
NULLHWND, /* hMenu */
0, /* hInst */
0L); /* lpParam */
CreateChildren(hPanel2);
hPanel3= _CreateWindow((PSTR) "Panel", /* class */
(PSTR) "Panel3", /* title */
WIN_HAS_BORDER | WIN_HAS_SHADOW | SHADOW_BOTRIGHT |
WIN_SYSMENU | WIN_TITLEBAR | WIN_MINMAXBOX |
WIN_VSCROLL | WIN_HSCROLL | WIN_MOVEBOX | WIN_SIZEBOX |
WS_CLIP,
44,9, 30,14, /* x,y,width,height */
MAKE_ATTR(WHITE, BLACK),
2, /* id */
hMain, /* hParent */
NULLHWND, /* hMenu */
0, /* hInst */
0L); /* lpParam */
CreateChildren(hPanel3);
/*
Show the window
*/
ShowWindow(hMain, TRUE);
BringWindowToTop(hPanel1);
SetFocus(hPanel1);
CheckMenuItem(GetMenu(hMain), ID_CHILDDEMO, MF_CHECKED);
}
long PASCAL PanelWndProc(HWND hWnd, WORD message, WORD wParam, LONG lParam)
{
switch (message)
{
case WM_MOUSEACTIVATE :
BringWindowToTop(hWnd);
return MA_ACTIVATEANDEAT;
case WM_CHAR :
switch (wParam)
{
case VK_DOWN:
ScrollWindow(hWnd, 0, 1, (LPRECT) NULL, (LPRECT) NULL);
break;
case VK_UP :
ScrollWindow(hWnd, 0, -1, (LPRECT) NULL, (LPRECT) NULL);
break;
case VK_LEFT:
ScrollWindow(hWnd, -1, 0, (LPRECT) NULL, (LPRECT) NULL);
break;
case VK_RIGHT:
ScrollWindow(hWnd, 1, 0, (LPRECT) NULL, (LPRECT) NULL);
break;
case VK_HOME:
ScrollWindow(hWnd, -1, -1, (LPRECT) NULL, (LPRECT) NULL);
break;
case VK_PGUP:
ScrollWindow(hWnd, 1, -1, (LPRECT) NULL, (LPRECT) NULL);
break;
case VK_END :
ScrollWindow(hWnd, -1, 1, (LPRECT) NULL, (LPRECT) NULL);
break;
case VK_PGDN:
ScrollWindow(hWnd, 1, 1, (LPRECT) NULL, (LPRECT) NULL);
break;
}
return TRUE;
case WM_CLOSE :
DestroyWindow(hWnd);
if (hWnd == hPanel1)
hPanel1 = NULLHWND;
else
if (hWnd == hPanel2)
hPanel2 = NULLHWND;
else
if (hWnd == hPanel3)
hPanel3 = NULLHWND;
if (!hPanel1 && !hPanel2 && !hPanel3)
CheckMenuItem(GetMenu(hMain), ID_CHILDDEMO, MF_UNCHECKED);
break;
default :
/* Call the default window procedure for the main window */
return DefWindowProc(hWnd, message, wParam, lParam);
}
return FALSE;
}
struct childinfo
{
char *szClass;
char *szTitle;
int x, y, cx, cy;
int id;
} ChildInfo[] =
{
{ "Text", "Business1:",1, 0,15,1, 24 } ,
{ "Edit", NULL, 20, 0,45,1, 25 },
{ "Text", "Business2:",1, 2,15,1, 24 } ,
{ "Edit", NULL, 20, 2,45,1, 25 },
{ "Text", "Business3", 1, 4,15,1, 24 } ,
{ "Edit", NULL, 20, 4,45,1, 25 },
{ "Text", "Business4", 1, 6,15,1, 24 } ,
{ "Edit", NULL, 20, 6,45,1, 25 } ,
{ "Text", "Business5", 1, 8,15,1, 24 } ,
{ "Edit", NULL, 20, 8,45,1, 25 },
/*
{ "Text", "Business6", 1,10,15,1, 24 } ,
{ "Edit", NULL, 20,10,45,1, 25 },
{ "Text", "Business7", 1,12,15,1, 24 } ,
{ "Edit", NULL, 20,12,45,1, 25 },
{ "Text", "Business8", 1,14,15,1, 24 } ,
{ "Edit", NULL, 20,14,45,1, 25 },
{ "Text", "Business9", 1,16,15,1, 24 } ,
{ "Edit", NULL, 20,16,45,1, 25 },
{ "Text", "Business0", 1,18,15,1, 24 } ,
{ "Edit", NULL, 20,18,45,1, 25 },
{ "Text", "BusinessA", 1,20,15,1, 24 } ,
{ "Edit", NULL, 20,20,45,1, 25 },
{ "Text", "BusinessB", 1,21,15,1, 24 } ,
{ "Edit", NULL, 20,21,45,1, 25 },
{ "Text", "BusinessC", 1,22,15,1, 24 } ,
{ "Edit", NULL, 20,22,45,1, 25 },
{ "Text", "BusinessD", 1,23,15,1, 24 } ,
{ "Edit", NULL, 20,23,45,1, 25 },
{ "Text", "BusinessE", 1,24,15,1, 24 } ,
{ "Edit", NULL, 20,24,45,1, 25 },
{ "Text", "BusinessF", 1,25,15,1, 24 } ,
{ "Edit", NULL, 20,25,45,1, 25 },
{ "Text", "BusinessG", 1,26,15,1, 24 } ,
{ "Edit", NULL, 20,26,45,1, 25 },
{ "Text", "BusinessH", 1,27,15,1, 24 } ,
{ "Edit", NULL, 20,27,45,1, 25 },
{ "Text", "BusinessI", 1,28,15,1, 24 } ,
{ "Edit", NULL, 20,28,45,1, 25 },
{ "Text", "BusinessJ", 1,29,15,1, 24 } ,
{ "Edit", NULL, 20,29,45,1, 25 },
{ "Text", "BusinessK", 1,30,15,1, 24 } ,
{ "Edit", NULL, 20,30,45,1, 25 },
{ "Text", "BusinessL", 1,31,15,1, 24 } ,
{ "Edit", NULL, 20,31,45,1, 25 },
{ "Text", "BusinessM", 1,32,15,1, 24 } ,
{ "Edit", NULL, 20,32,45,1, 25 },
*/
};
VOID CreateChildren(HWND hParent)
{
struct childinfo *pCI;
int i;
DWORD dwStyle = WS_CLIP;
RECT r;
WORD attr;
r = WinGetClient(hParent);
attr = WinGetAttr(hParent);
for (i = 0; i < sizeof(ChildInfo)/sizeof(ChildInfo[0]); i++)
{
pCI = &ChildInfo[i];
if (i & 0x01)
dwStyle |= WS_BORDER;
else
dwStyle &= ~WS_BORDER;
_CreateWindow((PSTR) pCI->szClass, (PSTR) pCI->szTitle,
dwStyle,
pCI->x+r.left, pCI->y+r.top, pCI->cx, pCI->cy,
attr, /* attr */
pCI->id, /* id */
hParent, /* hParent */
NULLHWND, /* hMenu */
0, /* hInst */
0L); /* lpParam */
}
_CreateWindow((PSTR) "PushButton", (PSTR) "Push Me!",
WS_BORDER,
1+r.left, r.bottom-2, 12, 3,
attr, /* attr */
100, /* id */
hParent, /* hParent */
NULLHWND, /* hMenu */
0, /* hInst */
0L); /* lpParam */
}
VOID TerminateChildDemo(VOID)
{
if (hPanel1)
SendMessage(hPanel1, WM_CLOSE, 0, 0L);
if (hPanel2)
SendMessage(hPanel2, WM_CLOSE, 0, 0L);
if (hPanel3)
SendMessage(hPanel3, WM_CLOSE, 0, 0L);
CheckMenuItem(GetMenu(hMain), ID_CHILDDEMO, MF_UNCHECKED);
}
/*===========================================================================*/
/* */
/* File : NOTEPAD.C */
/* */
/* Purpose : Demo of a multi-line edit field plus a new kind of button */
/* */
/*===========================================================================*/
#define MAXBUFSIZE 0xF000
static HWND hWndNotepad, hEdit;
static LPSTR pszFileToOpen = NULL;
int NotePad(VOID)
{
if (hWndNotepad)
{
BringWindowToTop(hWndNotepad);
SetFocus(hWndNotepad);
return TRUE;
}
MessageBox(hMain, "The notepad can only deal with 64K maximum",
"Warning", MB_OK);
EditBufferSize = MAXBUFSIZE;
hWndNotepad = CreateWindow("NotePad", /* class */
"NotePad", /* title */
WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_CLIP |
WS_MOVEBOX,
5,2, 60,20, /* x,y,width,height */
hMain, /* hParent */
NULLHWND, /* hMenu */
hInstance, /* hInst */
0L); /* lpParam */
hEdit = CreateWindow("Edit", /* class */
NULL, /* title */
ES_MULTILINE | WS_CHILD, /* dwStyle */
0,0, 56,16, /* x,y,width,height */
hWndNotepad, /* hParent */
NULLHWND, /* hMenu */
0, /* hInst */
0L); /* lpParam */
ShowWindow(hWndNotepad, SW_SHOW);
UpdateWindow(hWndNotepad);
BringWindowToTop(hWndNotepad);
SetFocus(hEdit);
return TRUE;
}
int NotepadOpenFile(BYTE *fname)
{
int fd;
HANDLE hBuf;
LPSTR pBuf;
if (!fname)
return FALSE;
hBuf = GlobalAlloc(GMEM_MOVEABLE, (DWORD) MAXBUFSIZE);
if (hBuf)
pBuf = (LPSTR) GlobalLock(hBuf);
if (!hBuf || !pBuf)
{
MessageBox(hMain, "Cannot alloc memory for reading",
"Error", MB_OK | MB_ICONEXCLAMATION);
return TRUE;
}
if ((fd = open((char *) fname, O_RDONLY)) < 0)
{
GlobalUnlock(hBuf);
GlobalFree(hBuf);
MessageBox(hMain, "Cannot open file for reading",
"Error", MB_OK | MB_ICONEXCLAMATION);
return TRUE;
}
else
{
int len;
WORD nBytes;
WORD nLeft = MAXBUFSIZE;
for (nBytes=0;
nLeft > 0 && (len = _lread(fd, pBuf+nBytes, min(0x7FFF, nLeft))) > 0;
nBytes += len)
nLeft -= len;
*(pBuf + nBytes) = '\0';
close(fd);
SendMessage(hEdit, WM_SETTEXT, 0, (LONG) pBuf);
GlobalUnlock(hBuf);
GlobalFree(hBuf);
}
return TRUE;
}
LONG PASCAL NotepadWndProc(HWND hWnd, WORD message, WORD wParam, LONG lParam)
{
char buf[128];
HANDLE pHandle;
switch (message)
{
case WM_COMMAND :
switch (wParam)
{
case ID_OPEN:
if (DlgOpenFile(NULLHWND, (PSTR) "*.txt", (PSTR) buf))
NotepadOpenFile((PSTR) buf);
break;
case ID_SAVE:
return BadCommand();
case ID_SAVEAS:
return BadCommand();
case ID_EXIT:
hWndNotepad = NULLHWND;
DestroyWindow(hWnd);
break;
case ID_CUT :
SendMessage(hEdit, WM_CUT, 0, 0L);
break;
case ID_CLEAR:
SendMessage(hEdit, WM_CLEAR, 0, 0L);
break;
case ID_COPY:
SendMessage(hEdit, WM_COPY, 0, 0L);
break;
case ID_PASTE:
SendMessage(hEdit, WM_PASTE, 0, 0L);
break;
case ID_GETLEN :
sprintf(buf, "There are %d characters",
SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0L));
MessageBox(hMain, buf, "Text Length", MB_OK);
break;
case ID_GETLINES:
sprintf(buf, "There are %d lines",
SendMessage(hEdit, EM_GETLINECOUNT, 0, 0L));
MessageBox(hMain, buf, "# of Lines", MB_OK);
break;
case ID_GETHANDLE:
pHandle = (HANDLE) SendMessage(hEdit, EM_GETHANDLE, 0, 0L);
sprintf(buf, "The edit handle is [%x]", pHandle);
MessageBox(hMain, buf, "Get Handle", MB_OK);
break;
}
break;
case WM_CLOSE :
hWndNotepad = NULLHWND;
DestroyWindow(hWnd);
return TRUE;
default :
/* Call the default window procedure for the main window */
return DefWindowProc(hWnd, message, wParam, lParam);
}
return TRUE;
}
int BadCommand(VOID)
{
MessageBox(hMain, "This command has not been implemented yet!",
"Error", MB_OK | MB_ICONHAND);
return TRUE;
}
/****************************************************************************/
/* */
/* Function : ComboDemo() */
/* */
/* Purpose : Shows all three styles of combo boxes */
/* */
/* Returns : */
/* */
/****************************************************************************/
#define ID_UDPATH 1000
#define ID_BUDPATH 1001
#define ID_CBFUTURES 1002
#define ID_CBEQUITIES 1003
#define ID_CBTICK 1004
#define ID_INDICES 1005
#define ID_HOLIDAYS 1006
VOID ComboDemo(void)
{
MessageBox(hMain,
"To pulldown the hidden listbox portion of a combobox,\n\
click on the combobox arrow icon or press F4 or ALT-GREY-DOWN.",
"Combo box demo", MB_OK);
DialogBox(hInstance, "UpdateSettings", hMain, ComboDialogProc);
}
int PASCAL ComboDialogProc(HDLG hDlg, WORD msg, WORD wParam, DWORD lParam)
{
int i;
static char *szColors[] =
{
"Black", "Blue", "Green", "Cyan",
"Red", "Magenta", "Yellow", "White",
NULL
};
(void) lParam;
switch (msg)
{
case WM_INITDIALOG :
SendDlgItemMessage(hDlg, ID_CBTICK, WM_SETREDRAW, FALSE, 0L);
for (i = 0; szColors[i]; i++)
SendDlgItemMessage(hDlg, ID_CBTICK, CB_ADDSTRING, 0, (DWORD) (LPSTR) szColors[i]);
SendDlgItemMessage(hDlg, ID_CBTICK, CB_SETCURSEL, 2, 0L);
i = (int) SendDlgItemMessage(hDlg, ID_CBTICK, CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, ID_CBTICK, WM_SETREDRAW, TRUE, 0L);
SendDlgItemMessage(hDlg, ID_CBFUTURES, WM_SETREDRAW, FALSE, 0L);
for (i = 0; szColors[i]; i++)
SendDlgItemMessage(hDlg, ID_CBFUTURES, CB_ADDSTRING, 0, (DWORD) (LPSTR) szColors[i]);
SendDlgItemMessage(hDlg, ID_CBFUTURES, CB_SETCURSEL, 6, 0L);
i = (int) SendDlgItemMessage(hDlg, ID_CBFUTURES, CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, ID_CBFUTURES, WM_SETREDRAW, TRUE, 0L);
SendDlgItemMessage(hDlg, ID_CBEQUITIES, WM_SETREDRAW, FALSE, 0L);
for (i = 0; szColors[i]; i++)
SendDlgItemMessage(hDlg, ID_CBEQUITIES, CB_ADDSTRING, 0, (DWORD) (LPSTR) szColors[i]);
SendDlgItemMessage(hDlg, ID_CBEQUITIES, CB_SETCURSEL, 2, 0L);
i = (int) SendDlgItemMessage(hDlg, ID_CBEQUITIES, CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, ID_CBEQUITIES, WM_SETREDRAW, TRUE, 0L);
return TRUE;
case WM_COMMAND :
switch (wParam)
{
case IDOK :
case IDCANCEL :
EndDialog(hDlg, TRUE);
break;
}
return TRUE;
}
return FALSE;
}
/**********************************************************************
* HEXCALC.C
*
* Converted to Mewel by Sal Ricciardi of PC Magazine
*
**********************************************************************/
int PASCAL CalcDlgProc (HWND, WORD, WORD, DWORD) ;
DWORD CalcIt (DWORD dwFirstNum, WORD nOperation, DWORD dwNum);
VOID ShowNumber (HWND hWnd, DWORD dwNumber);
int Calculator(VOID)
{
static BYTE szAppName[] = "HexCalc" ;
if (hWndCalc)
{
BringWindowToTop(hWndCalc);
SetFocus(hWndCalc);
return TRUE;
}
MessageBox(NULLHWND,
"The Calculator is a POPUP window, and will stay in front of all other \
non-popup windows (like the notepad).",
"Note", MB_OK);
if ((hWndCalc = CreateDialog(hInstance, szAppName, hMain, CalcDlgProc)) != NULL)
{
// SetMenu(hWndCalc, LoadMenu(hInstance, (LPSTR) "DlgBoxMenu"));
ShowWindow(hWndCalc, SW_SHOW);
SetFocus(hWndCalc);
}
else
{
MessageBox(hMain, "Could not load calculator", "Error", MB_OK);
}
return TRUE;
}
VOID ShowNumber(HWND hWnd, DWORD dwNumber)
{
BYTE szBuffer[20] ;
#ifndef UNIX
SetDlgItemText(hWnd, VK_ESCAPE,
(PSTR) strupr(ltoa(dwNumber, (char *) szBuffer, 16))) ;
#endif
}
DWORD CalcIt(DWORD dwFirstNum, WORD nOperation, DWORD dwNum)
{
switch (nOperation)
{
case '=' : return dwNum ;
case '+' : return dwFirstNum + dwNum ;
case '-' : return dwFirstNum - dwNum ;
case '*' : return dwFirstNum * dwNum ;
case '&' : return dwFirstNum & dwNum ;
case '|' : return dwFirstNum | dwNum ;
case '^' : return dwFirstNum ^ dwNum ;
case '<' : return dwFirstNum << dwNum ;
case '>' : return dwFirstNum >> dwNum ;
case '/' : return dwNum ? dwFirstNum / dwNum : ULONG_MAX ;
case '%' : return dwNum ? dwFirstNum % dwNum : ULONG_MAX ;
default : return 0L ;
}
}
int PASCAL CalcDlgProc(HWND hWnd, WORD iMessage, WORD wParam, DWORD lParam)
{
static BOOL bNewNumber = TRUE ;
static DWORD dwNumber, dwFirstNum ;
static short nOperation = '=' ;
HWND hButton ;
(void) lParam;
switch (iMessage)
{
case WM_KEYDOWN: /* left arrow --> backspace */
if (wParam != VK_LEFT)
break ;
wParam = VK_BACK ; /* fall through */
case WM_CHAR:
switch (toupper(wParam))
{
case VK_DOWN:
case VK_RIGHT:
wParam = VK_TAB;
return FALSE;
case VK_UP:
case VK_LEFT:
wParam = VK_BACKTAB;
return FALSE;
case VK_TAB:
case VK_BACKTAB:
return FALSE;
default:
break;
}
if ((wParam = toupper(wParam)) == VK_RETURN)
wParam = (WORD) '=';
if ((hButton = GetDlgItem(hWnd, wParam)) != NULL)
{
SendMessage (hButton, BM_SETSTATE, 1, 0L) ;
SendMessage (hButton, BM_SETSTATE, 0, 0L) ;
SetFocus (hButton) ;
}
else
{
MessageBeep (0) ;
break ;
} /* fall through */
case WM_COMMAND:
if (wParam == ID_ABOUT)
{
MessageBox(hWnd, (PSTR) "Calculator Demo",
(PSTR) "About MEWEL", MB_OK | MB_ICONEXCLAMATION);
break;
}
else if (wParam == ID_EXIT)
{
PostMessage(hWnd, WM_CLOSE, 0, 0L);
break;
}
SetFocus (hWnd) ;
if (wParam == VK_BACK) /* backspace */
ShowNumber (hWnd, dwNumber /= 16) ;
else if (wParam == VK_ESCAPE) /* escape */
ShowNumber (hWnd, dwNumber = 0L) ;
else if (isxdigit (wParam)) /* hex digit */
{
if (bNewNumber)
{
dwFirstNum = dwNumber ;
dwNumber = 0L ;
}
bNewNumber = FALSE ;
if (dwNumber <= (ULONG_MAX >> 4))
ShowNumber (hWnd, dwNumber = 16 * dwNumber + wParam -
(isdigit (wParam) ? '0' : 'A' - 10)) ;
else
MessageBeep (0) ;
}
else /* operation */
{
if (!bNewNumber)
ShowNumber (hWnd, dwNumber =
CalcIt (dwFirstNum, nOperation, dwNumber)) ;
bNewNumber = TRUE ;
nOperation = wParam ;
}
break ;
case WM_CLOSE :
hWndCalc = NULLHWND;
DestroyWindow(hWnd);
break;
default :
return FALSE;
}
return TRUE;
}
/**************************************************************************/
/* */
/* SCRLDEMO.C - demonstration of the usage of scroll bars.... */
/* */
/**************************************************************************/
int PrintScrollbarValues(WORD message, WORD wParam, LONG lParam)
{
char *pszMsg;
char buf[80];
HWND hSB;
int minpos, maxpos, currpos;
HDC hDC;
HBRUSH hBrush;
RECT r;
(void) message;
hSB = HIWORD(lParam); /* HIWORD(lParam) has the scrollbar handle */
currpos = GetScrollPos(hSB, SB_CTL);
GetScrollRange(hSB, SB_CTL, &minpos, &maxpos);
switch (wParam)
{
case SB_LINEUP :
SetScrollPos(hSB, SB_CTL, max(currpos-1, minpos), TRUE);
currpos = GetScrollPos(hSB, SB_CTL);
pszMsg = "SB_LINEUP";
break;
case SB_LINEDOWN :
SetScrollPos(hSB, SB_CTL, min(currpos+1, maxpos), TRUE);
currpos = GetScrollPos(hSB, SB_CTL);
pszMsg = "SB_LINEDOWN";
break;
case SB_PAGEUP :
SetScrollPos(hSB, SB_CTL, max(currpos-10, minpos), TRUE);
currpos = GetScrollPos(hSB, SB_CTL);
pszMsg = "SB_PAGEUP";
break;
case SB_PAGEDOWN :
SetScrollPos(hSB, SB_CTL, min(currpos+10, maxpos), TRUE);
currpos = GetScrollPos(hSB, SB_CTL);
pszMsg = "SB_PAGEDOWN";
break;
case SB_THUMBTRACK :
pszMsg = "SB_THUMBTRACK";
goto do_it;
case SB_THUMBPOSITION :
pszMsg = "SB_THUMBPOSITION";
goto do_it;
case SB_ENDSCROLL :
pszMsg = "SB_ENDSCROLL";
do_it:
currpos = LOWORD(lParam);
SetScrollPos(hSB, SB_CTL, max(min(currpos, maxpos), minpos), TRUE);
currpos = GetScrollPos(hSB, SB_CTL);
break;
}
/*
This is the low-level MEWEL way of clearing out a window and writing text
to it. For Windows compatibility, you can do a GetDC, FillRect, TextOut,
and ReleaseDC, with SetTextColor and SetBkColor thrown in for good
measure.
*/
sprintf(buf, "Msg [%s] Pos [%3d] %3d%% ",
pszMsg, currpos, currpos * 100 / maxpos);
#if 1
WinEraseEOL(hMsgWnd, 0, 0, 0x31);
WinPuts(hMsgWnd, 0, 0, (PSTR) buf, 0x31);
#else
hDC = GetDC(hMsgWnd);
SetTextColor(hDC, RGB(0, 0, 128));
SetBkColor(hDC, RGB(0, 128, 128));
hBrush = CreateSolidBrush(RGB(0, 128, 128));
GetClientRect(hMsgWnd, (LPRECT) &r);
FillRect(hMsgWnd, (LPRECT) &r, hBrush);
DeleteObject(hBrush);
TextOut(hDC, 0, 0, buf, strlen(buf));
ReleaseDC(hMsgWnd, hDC);
#endif
return TRUE;
}
/****************************************************************************/
/* */
/* Function : GraphicsModeDemo */
/* */
/* Purpose : Shows how MEWEL can work in graphics mode. */
/* */
/* Returns : */
/* */
/****************************************************************************/
VOID GraphicsModeDemo(VOID)
{
static int oldMode = -1;
static BOOL bGraphics = FALSE;
#ifdef DOS
if (bGraphics)
{
VidSetVideoMode(oldMode);
bGraphics = FALSE;
CheckMenuItem(GetMenu(hMain), ID_GRAPHICS, MF_UNCHECKED | MF_BYCOMMAND);
}
else
{
oldMode = VidGetMode();
if (!IsEGA() && !IsVGA())
{
MessageBox(hMain, "You must have an EGA/VGA monitor for this one",
"Graph Demo", MB_OK | MB_ICONEXCLAMATION);
return;
}
VidSetVideoMode(0x10);
bGraphics = TRUE;
CheckMenuItem(GetMenu(hMain), ID_GRAPHICS, MF_CHECKED | MF_BYCOMMAND);
}
#endif
}
/****************************************************************************/
/* */
/* Function : VideoModeDemo */
/* */
/* Purpose : Toggles MEWEL between 25 and 43/50 line mode. */
/* */
/* Returns : */
/* */
/****************************************************************************/
VOID VideoModeDemo(VOID)
{
#if defined(DOS) || defined(OS2)
if (IsEGA() || IsVGA())
{
ToggleEGA();
ChangeMenu(GetMenu(hMain), ID_TOGGLEEGA,
(GetSystemMetrics(SM_CYSCREEN) <= 25) ? "43/50 Line Mode"
: "25 Line Mode",
0,
MF_STRING | MF_BYCOMMAND | MF_CHANGE);
}
else
{
MessageBox(NULLHWND, "Sorry. You need an EGA or VGA", "Toggle Demo",
MB_OK | MB_ICONEXCLAMATION);
}
#endif
}
/****************************************************************************/
/* */
/* Function : DOSEscape() */
/* */
/* Purpose : Demo of the ability to spawn a program with the entirety */
/* of MEWEL swapped out to EMS or to disk */
/* Returns : */
/* */
/****************************************************************************/
VOID DOSEscape(VOID)
{
#ifndef UNIX
MessageBox(hMain,
"This will exec a copy of COMMAND.COM two times.\n\
The first time, the entire MEWEL session will be swapped to disk or\n\
to EMS, and the second time, COMMAND.COM will be spawned without swapping\n\
the MEWEL session out. Type EXIT at the DOS prompt to return to MEWEL.",
(PSTR) "DOS Demo", MB_OK);
#ifndef DOS286X
MessageBox(hMain, "Execing with swapping", "Swap", MB_OK);
WinExec(NULL, TRUE);
#endif
MessageBox(hMain, "Execing without swapping", "Swap", MB_OK);
WinExec(NULL, FALSE);
#endif
}
/****************************************************************************/
/* */
/* Function : memavail() */
/* */
/* Purpose : Returns the amount of available memory. */
/* */
/* Returns : */
/* */
/****************************************************************************/
#ifdef DOS
/*
For the 386 DOS Extenders, we need to redefine the way that int86()
is called.
*/
#if defined(__WATCOMC__) && defined(__386__)
#define ax eax
#define bx ebx
#define cx ecx
#define dx edx
#define int86 int386
#endif
long memavail(VOID)
{
union REGS regs;
regs.h.ah = 0x48;
regs.x.bx = 0xFFFF;
int86(0x21, ®s, ®s);
return(16L * regs.x.bx);
}
#endif